package com.hry.springboot.sharding.jdbc.controller;

import com.hry.springboot.sharding.jdbc.dao.SmartDeviceStudentCourseMapper;
import com.hry.springboot.sharding.jdbc.dao.SmartDeviceStudentMapper;
import com.hry.springboot.sharding.jdbc.entity.SmartDeviceStudent;
import com.hry.springboot.sharding.jdbc.entity.SmartDeviceStudentCourse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2021/8/13
 **/
@RestController
public class TestController {

    @Autowired
    private SmartDeviceStudentCourseMapper smartDeviceStudentCourseMapper;

    @Autowired
    private SmartDeviceStudentMapper smartDeviceStudentMapper;

    @GetMapping("test")
    public String test(Long id, Long userId) {
        SmartDeviceStudentCourse course = new SmartDeviceStudentCourse();
        course.setId(id);
        course.setUserId(userId);


        smartDeviceStudentCourseMapper.insert(course);


        return "success";
    }

    @GetMapping("getById")
    public String getById(Long id) {
        SmartDeviceStudentCourse byId = smartDeviceStudentCourseMapper.getById(id);
        return byId.toString();
    }

    @GetMapping("getByUserId")
    public String getByUserId(Long userId) {
        SmartDeviceStudentCourse byUserId = smartDeviceStudentCourseMapper.getByUserid(userId);
        return byUserId.toString();
    }


    @GetMapping("student")
    public String student(Long id) {
        SmartDeviceStudent student = smartDeviceStudentMapper.getById(id);
        return student.toString();
    }

}
